<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="apple-mobile-web-app-title" content="阿福易购">
    <meta content="telephone=no" name="format-detection" />
    <meta content="email=no" name="format-detection" />
    <!-- uc、qq浏览器 -->
    <meta name="screen-orientation" content="portrait">
    <meta name="full-screen" content="yes">
    <meta name="browsermode" content="application">
    <meta name="x5-orientation" content="portrait">
    <meta name="x5-fullscreen" content="true">
    <meta name="x5-page-mode" content="app">
    <meta name="HandheldFriendly" content="true">
    <meta name="MobileOptimized" content="320">
    <meta name="csrf-token" content="{{ csrf_token() }}" />
    <meta name="keywords" content="{{$SEO['keywords']}}"/>
    <meta name="description" content="{{$SEO['description']}}"/>
    <title>商品详情_{{$SEO['title']}}</title>
    <link rel="stylesheet" href="{{ asset('/build/css/app.min.css') }}">
</head>
<body id="goodsInfo" ontouchstart="">
<header class="ui-header ui-header-stable  af-header">
    <ul class="ui-row-flex">
        <li class="ui-col ui-flex ui-flex-pack-start">
            <i ontouchstart="window.history.back();" class="ui-icon-return"></i>
        </li>
        <li class="ui-col ui-flex ui-flex-pack-center">
            <h1>商品详情</h1>
        </li>
        <li class="ui-col ui-flex ui-flex-pack-end">
            <i class="ui-icon-home" data-href="/"></i>
        </li>
    </ul>
</header>

<footer class="ui-footer ui-goods-footer">
    <div class="ui-row-flex">
        <div class="ui-col">
            <div class="ui-row-flex">
                <div class="ui-col J-fav" data-id="{{$goods->goods_id}}" data-status="{{$goodsCollectionStatus}}"><i class="ui-icon-trend @if($goodsCollectionStatus==1) af-txt-highlight @endif"></i></div>
                <div class="ui-col">
                    <div data-href="/cart" class="ui-badge-wrap">
                        <i class="ui-icon-cart af-txt-highlight"></i>

                        <div class="J-carNum ui-badge-cornernum @if($cartNumber==0) af-hide @endif">{{$cartNumber}}</div>

                    </div>
                </div>
            </div>
        </div>
        <div class="ui-col">
            <button id="buy" class="ui-btn ui-btn-buy">立即购买</button>
        </div>
        <div class="ui-col">
            <button id="addCartBtn" class="ui-btn ui-btn-cart">加入购物车</button>
        </div>
    </div>

</footer>
@inject('pictureService','App\Interfaces\PictureService')
@inject('commentService','App\Interfaces\CommentService')
@inject('shopService','App\Interfaces\ShopService')

@inject('couponService','App\Interfaces\CouponService')
<?php //goods_discount_tip?>
<section id="goodsCover" class="ui-cover-wrap" data-id="{{$goods->goods_id}}">
    <ul class="ui-cover-scroll">
        <li class="ui-cover-mask"></li>
        <li class="J-cover ui-cover" data-id="{{$goods->goods_id}}">
            <div class="ui-header ui-header-stable af-header">
                <ul class="ui-row-flex">
                    <li class="ui-col ui-flex ui-flex-pack-start">
                        <i class="ui-icon-return"></i>
                    </li>
                    <li class="ui-col ui-flex ui-flex-pack-center">
                        <h1>规格选择</h1>
                    </li>
                    <li class="ui-col ui-flex ui-flex-pack-end">
                    </li>
                </ul>
            </div>

            <div class="ui-container">
                <ul class="ui-list af-border-tb ui-goods-list">
                    <li>
                        <div class="ui-list-icon">
                            <span class="J-thumb" style="background-image:url('{{$pictureService::thumb($goods->goods_thumb),800,800}}')"></span>
                        </div>
                        <div class="ui-list-info">
                            <h4 class="J-name ui-nowrap">{{$goods->goods_name}}</h4>
                            <?php $goodsArr = $goods->toArray();?>
                            <p><span class="J-price af-txt-highlight">￥{{$goodsArr['goods_real_price']}}</span></p>
                        </div>
                    </li>

                </ul>
                {{--sku--}}
                @if($productAttributeArr)
                <div class="ui-tags-list af-border-b ">
                @foreach($productAttributeArr as $productAttribute)
                    <h2>{{$productAttribute['attribute_name']}}</h2>
                    <ul>
                    @foreach($productAttribute['attribute_value_arr'] as $attributeValue)
                        <li><a data-id="{{$attributeValue['attribute_value_id']}}" class="ui-tag @if($attributeValue['attribute_value_status']==1) current @endif">{{$attributeValue['attribute_value_name']}}</a></li>
                    @endforeach
                    </ul>
                @endforeach
                </div>
                @endif
                <ul class="ui-list ui-list-text">
                    <li>
                        <div class="ui-list-info">
                            <span class="af-txt-muted">数量</span>
                            <div class="ui-num-plugin af-border-tb @if($goods->goods_number==0) af-hide @endif">
                                <button class="af-border-l af-border-r ui-num-btn ui-num-min">-</button>
                                <input class="ui-num-input" type="text" value="1" min="1" max="{{$goods->goods_number}}" readonly>
                                <button class="af-border-l af-border-r ui-num-btn ui-num-add">+</button>
                            </div>

                            <span class="J-stock ui-txt-info" style="margin-left: 10px">@if($goods->goods_number>0) (库存：{{$goods->goods_number}}) @else 库存不足 @endif</span>

                        </div>
                    </li>
                </ul>

            </div>
            <div class="ui-footer af-footer ui-goods-footer">
                <button class="J-btn ui-btn ui-btn-cart">立即购买</button>
            </div>
        </li>
    </ul>
</section>

<div class="ui-container ui-goods">
    <section class="ui-goods-slider af-border-b">
        <div class="ui-slider">
            <ul class="ui-slider-content" style="width: 300%">
                <li class="current"><span style="background-image:url('{{$pictureService::thumb($goods->goods_thumb),800,800}}')"></span></li>
                @if($goodsGallery->count())

                <?php
                    $goods_pic = $goodsGallery->toArray()[0];
                    for ($i=1; $i < 9; $i++) {
                    $pic = $goods_pic['pic_'.$i];
                ?>
                @if(!empty($pic))
                <li><span style="background-image:url('{{$pictureService::thumb($pic),800,800}}')"></span></li>
                @endif
                <?php
                    }
                ?>
                @endif
            </ul>
        </div>
    </section>
    <section class="ui-panel ui-panel-simple ui-goods-header">
        <h2>{{$goods->goods_name}} @if($goods->shop_id==5)<label class="ui-label-s ui-label-light">自营</label>@endif</h2>
        <h3 class="ui-panel-subtitle">{{$goods->goods_pet_name}}</h3>
    </section>
<?php $discountTypeArr=['1'=>'全场通用','2'=>'商品','3'=>'分类','4'=>'店铺','5'=>'品牌']; ?>
    <section class="ui-panel ui-panel-simple ui-goods-price">
        <h2 class="af-border-b"><span class="af-txt-highlight">￥{{$goodsArr['goods_real_price']}}</span><del class="ui-txt-space">￥{{$goods->shop_price}}</del></h2>
        @if($goodsArr['goods_discount_tip'])
        <h2><span class="af-txt-muted">折扣<label class="ui-label-s ui-label-light">限时折扣</label><label class="ui-txt-highlight">     {{$discountTypeArr[$goodsArr['discount']['discount_type']]}}类型     {{$goodsArr['discount']['discount_label']}}</label></span>
        @endif
        <h2><span class="af-txt-muted">运费</span>
        @if($goods->type==0)
        <span class="param-item">
            <?php $shipFei=config('shipping-price'); ?>
            @if($goods->shop_price>=$shipFei['freePostAmount'])
                <label class="ui-label-s ui-label-light">包邮</label>
            @elseif($address&&($address->position_ids[0] == 650000 || $address->position_ids[0] == 540000))
               <span class="ui-txt-space af-txt-highlight"><i class="js-expressPrice">15</i>元</span>
            @else
               <span class="ui-txt-space af-txt-highlight"><i class="js-expressPrice">7</i>元</span>
            @endif
        </span>
        @endif
        </h2>
    </section>

    <section class="ui-panel ui-panel-simple">
        <h2 id="goodsNum" class="ui-arrowlink"><span class="af-txt-muted">已选<i>1</i>件商品</span></h2>
    </section>

    <?php
        $coupons = @$couponService->getCanReceiveCoupon(@$goods->goods_id);

        $num = 0;

        foreach ($coupons as $key => $item) {

            if($item->amount<=$item->receive_amount) continue;

            $num++;
        }
    ?>
    @if(@$coupons && $num>0)
    <section class="ui-panel ui-panel-simple">
        <h2 class="ui-arrowlink" data-href="/goods/coupon/{{@$goods->goods_id}}"><span class="af-txt-muted">有{{$num}}张优惠券可领取</span></h2>
    </section>
    @endif

    <section class="ui-panel ui-panel-simple">
            <h2 class="J-areaWrap">
                <span class="af-txt-muted">送至</span>
                <i class="ui-icon-pin af-txt-highlight" style="line-height: 34px;"></i>
                <input id="areaInput" type="text" class="af-txt-muted ui-goods-address" value="" readonly>
                <input id="areaIds" type="hidden" value="@if($address){{$address->position_ids}}@endif">
            </h2>
    </section>
    <ul class="ui-goods-bz ui-whitespace">
        <li><i class="ui-icon-success"></i><span>正品保障</span></li>
        <li><i class="ui-icon-success"></i><span>告别传统海淘漫长等待</span></li>
        <li><i class="ui-icon-success"></i><span>支付便捷售后无忧</span></li>
    </ul>
    <?php
        $commPercent=$commentService->countComment($goods->goods_id)==0?100:number_format((($commentService->countGoodComment($goods->goods_id))/($commentService->countComment($goods->goods_id))*100),0);
    ?>
    <section class="ui-panel ui-panel-simple">
        <h2 data-href="/goods/comment/{{$goods->goods_id}}" class="ui-arrowlink"><span class="af-txt-muted">评论({{$commentService->countComment($goods->goods_id)}})</span><span class="ui-panel-title-tips">好评<em>{{$commPercent}}%</em></span></h2>
    </section>

    <ul class="ui-list ui-list-one ui-list-link ui-goods-shop af-border-tb">
        <li>
            <div class="ui-list-thumb">
                <span style="background-image:url('{{$pictureService::thumb($shop->shop_logo),280,140}}')"></span>
            </div>
            <div class="ui-list-info">
                <h4 class="ui-nowrap">{{$shop->shop_name}}</h4>
                <div data-href="/shop/{{$shop->id}}" class="ui-txt-info">进入店铺</div>
            </div>
        </li>
    </ul>


    <section class="ui-panel ui-panel-simple ui-goods-detail">
     <div class="pre">
        <div style="text-align:left">{!! $goods->goods_content !!}</div>
     </div>
    </section>
</div>

<script src="{{ asset('/build/lib/zepto.min.js') }}"></script>
<script src="{{ asset('/build/js/frozen.js') }}"></script>
<script src="{{ asset('/build/js/app.min.js') }}"></script>
<link rel="stylesheet" href="/build/js/LArea/LArea.min.css">
<script src="/build/js/LArea/LAreaData1.js"></script>
<script src="/build/js/LArea/LArea.min.js"></script>
<script>
    var pageConfig={
        changeAttribute:'/goods/get_redirect_goods',//选择商品属性
        buy:'/cart/fast_settlement',//立即购买 验证
        order:'/order?from=detail',//立即购买 验证成功后跳转订单页
        addCart:'/cart' //加入购物车

    };
    goodsFun(pageConfig);
    //省市区
    initAreaSelect({
        trigger:'#areaInput',
        valueTo:'#areaIds'
    });
</script>
<script>
    $(function () {
        $('.J-fav').on('click',function () {
            var that=$(this),id=that.attr('data-id'),status=that.attr('data-status'), classItem=that.find('i');
            var data={
                type:'GOODS',
                reference_id:id,
                _token:_token
            };
            if(status==1){
                $.ajax({
                    url:'/collection/cancel',type:'post',dataType:'json',data:data,
                    success:function (res) {
                        if(res.id){
                            classItem.removeClass("af-txt-highlight");
                            that.attr('data-status',0);
                            topTip('已取消收藏');
                        }
                    },
                    error:function (error) {
                        topTip(error.message||'服务器忙，请刷新重试');
                    }
                })
            }else{
                $.ajax({
                    url:'/collection/add',type:'post',dataType:'json',data:data,
                    success:function (res) {
                        if(res.id){
                            classItem.addClass("af-txt-highlight");
                            that.attr('data-status',1);
                            topTip('已收藏');
                        }
                    },

                    error:function (error) {
                        topTip(error.message||'服务器忙，请刷新重试');
                    }
                })
            }
        });
    })
</script>
</body>
</html>